<template>
  <div class="item" style="width: 100%">
    <div class="name">{{ item.name }}</div>
    <div class="manager">{{ item.manager }}</div>
    <el-dropdown class="dropdown" @command="commandEvent">
      <span>
        <span>操作</span>
        <i class="el-icon-arrow-down" />
      </span>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item command="add">添加子部门</el-dropdown-item>
          <el-dropdown-item v-if="!item.top" command="look">部门查看</el-dropdown-item>
          <el-dropdown-item v-if="!item.top" command="del">删除部门</el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>

<script>
// 导入删除
import { companyDepartmentDelete } from '@/api/departments.js'
export default {
  props: {
    item: {
      type: Object,
      default: () => ({})
    }
  },
  methods: {
    commandEvent(command) {
      switch (command) {
        case 'add':
          // alert('add')
          this.$but.$emit('changeShow', true, this.item, 'add')
          break
        case 'look':
          // alert('look')
          this.$but.$emit('changeShow', true, this.item, 'edit')
          break
        case 'del':
          // alert('del')
          this.$confirm(`你确定删除该部门:[${this.item.name}]吗`, '提示')
            .then(async() => {
              await companyDepartmentDelete(this.item.id)
              this.$message.success('删除成功')
              this.$emit('getDate')
            })
            .catch(() => {})
          break
      }
    }
  }
}
</script>

<style lang="scss" scoped>
  .item{
  display: flex;
  .name{
    flex: 1;
  }
  .manager{
    width: 80px;
    margin-right: 10px;
  }
}
</style>
